/** * 左边菜单 */
<template>
  <!-- <el-menu :collapse="collapsed" collapse-transition router :default-active="this.$route.path" unique-opened class="el-menu-vertical-demo" background-color="#334157" text-color="#fff" active-text-color="#333">
    <div class="logobox">
      <img class="logoimg" src="../assets/img/logo.png" alt="">
    </div>
    <el-menu-item v-for="menu in allmenu" :key="menu.menuid" :index="menu.url">
      <i class="iconfont" :class="menu.icon"></i>
      <span slot="title">{{menu.menuname}}</span>
    </el-menu-item>
  </el-menu> -->
  <el-menu :collapse="collapsed" collapse-transition router :default-active="activMenu" unique-opened class="el-menu-vertical-demo" background-color="#334157" text-color="#fff" active-text-color="#333" @select="select">
    <div class="logobox">
      <img class="logoimg" src="../assets/img/logo.png" alt="" />
    </div>
    <div class="logobox logoboxO">
      <div class="VR_student" v-show="isVal" :class="collapsed">VR教学管理平台</div>
    </div>
    <el-menu-item v-for="menu in allmenu" :key="menu.key" :index="menu.key" :route="menu.path">
      <i :class="menu.meta.icon"></i>
      <span slot="title">{{ menu.meta.title }}</span>
    </el-menu-item>
  </el-menu>
</template>

<script>
import { menu } from '../api/userMG'
import menuNav from '@/router/menuNav'

export default {
  name: 'leftnav',
  data() {
    return {
      collapsed: false,
      allmenu: [],
      isVal: true,  // 控制标题显示隐藏
    }
  },
  mounted() {
  },
  computed:{
    activMenu(){
      return this.$route.meta.sideActiveName||this.$route.name;
    }
  },
  // 创建完毕状态(里面是操作)
  created() {
    let menuNavfind = menuNav.find(item => item.path === '/').children
    // 获取图形验证码
    let res = {
      success: true,
      data: [
        {
          icon: 'el-icon-files',
          menuname: '概览',
          url: '/overviewOf'
        },
        {
          menuid: 33,
          icon: 'el-icon-notebook-2',
          menuname: '课件',
          hasThird: null,
          url: '/content'
        },
        {
          menuid: 34,
          icon: 'el-icon-copy-document',
          menuname: '用户',
          hasThird: null,
          url: '/theUser'
        },
        // {
        //   menuid: 35,
        //   icon: 'el-icon-dish',
        //   menuname: '机构',
        //   hasThird: null,
        //   url: '/institutions'
        // },
        {
          menuid: 36,
          icon: 'el-icon-lock',
          menuname: '设备',
          hasThird: null,
          url: '/equipment'
        },
        {
          menuid: 37,
          icon: 'el-icon-pie-chart',
          menuname: '统计',
          hasThird: null,
          url: '/statistical'
        },
        {
          menuid: 38,
          icon: 'el-icon-setting',
          menuname: '设置',
          hasThird: null,
          url: '/setUpThe'
        }
      ],
      msg: 'success'
    }
    this.allmenu = menuNavfind
    // menu(localStorage.getItem('logintoken'))
    //   .then(res => {
    //     console.log(JSON.stringify(res))
    //     if (res.success) {
    //       this.allmenu = res.data
    //     } else {
    //       this.$message.error(res.msg)
    //       return false
    //     }
    //   })
    //   .catch(err => {
    //     this.$message.error('菜单加载失败，请稍后再试！')
    //   })
    // 监听
    this.$root.Bus.$on('toggle', value => {
      this.isVal = value;
      this.collapsed = !value;
    })
  },
  methods: {
    // 这个是饿了么导航菜单点击选中某一个时清楚存储的数据
    select(index) {
      sessionStorage.removeItem('userData');
      sessionStorage.removeItem('userDataS');
      sessionStorage.removeItem('jumpListUser');
      sessionStorage.removeItem('toViewRow');
      sessionStorage.removeItem('curriculm');
      sessionStorage.removeItem('statusChange');
      sessionStorage.removeItem('add');
      sessionStorage.removeItem('reportRi');
      sessionStorage.removeItem('Today');
      sessionStorage.removeItem('versionAdd');
      sessionStorage.removeItem('routerThis');
    }
  }
}
</script>

<style scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) { width: 140px; min-height: 400px; }
.el-menu-vertical-demo:not(.el-menu--collapse) { border: none; text-align: left; }
.el-menu-item-group__title { padding: 0px; }
.el-menu-bg { background-color: #1f2d3d !important; }
.el-menu { border: none; }
.logobox { /* height: 40px; */ line-height: 40px; color: #9d9d9d; font-size: 20px; text-align: center; padding: 30px 0 10px; }
.logoboxO{ padding: 0 !important;height: 40px;margin-bottom: 5px; }
.logoimg { height: 40px; }
.VR_student { width: 100%; display: block; box-sizing: border-box; font-size: 16px; color: #fff; font-weight: 600;}
.act{ opacity: 0; }
/* //设置鼠标悬停时el-menu-item的样式 */
.el-menu-item:hover { background-color: #e2eff9 !important; color: #38b2ff !important; /* //less语法，实现鼠标悬停时icon变色 */ }
.el-menu-item:hover > i { color: #38b2ff; }
/* //设置选中el-menu-item时的样式 */
.el-menu-item.is-active { background-color: #e2eff9 !important; color: #38b2ff !important; }
</style>
